package com.elinshaw;

/**
 * @author eLinShaw
 */
public class InternalTask implements Runnable {

    private final RunnableQueue runnableQueue;

    private volatile boolean running = true;

    public InternalTask(RunnableQueue runableQueue) {
        this.runnableQueue = runableQueue;
    }

    @Override
    public void run() {
        /**
         * 如果当前任务running且没有被中断
         */
        while (running && !Thread.currentThread().isInterrupted()) {
            try {
                Runnable task = runnableQueue.take();
                task.run();
            } catch (InterruptedException e) {
                running = false;
                break;
            }
        }
    }


    /**
     * 停止当前任务
     */
    public void stop() {
        this.running = false;
    }

}
